//
// * Copyright (c) 2002-2010 "Neo Technology,"
// *     Network Engine for Objects in Lund AB [http://neotechnology.com]
// *
// * This file is part of Neo4j.
// * 
// * Neo4j is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Affero General Public License as
// * published by the Free Software Foundation, either version 3 of the
// * License, or (at your option) any later version.
// * 
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// * GNU Affero General Public License for more details.
// * 
// * You should have received a copy of the GNU Affero General Public License
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
// 
using System.Collections.Generic;
using org.neo4j.graphdb;
using Node = org.neo4j.graphdb.Node;
using Relationship = org.neo4j.graphdb.Relationship;
using RelationshipType = org.neo4j.graphdb.RelationshipType;
using Transaction = org.neo4j.graphdb.Transaction;
using TransactionFailureException = org.neo4j.kernel.impl.transaction.TransactionFailureException;

namespace org.neo4j.kernel
{




///
/// <summary> * An implementation of <seealso cref="GraphDatabaseService"/> that is used to embed Neo4j
/// * in an application. You typically instantiate it by invoking the
/// * <seealso cref="#EmbeddedGraphDatabase(String) single argument constructor"/> that takes
/// * a path to a directory where Neo4j will store its data files, as such:
/// * 
/// * <pre>
/// * <code>
/// * GraphDatabaseService graphDb = new EmbeddedGraphDatabase( &quot;var/graphdb&quot; );
/// * // ... use Neo4j
/// * graphDb.shutdown();
/// * </code>
/// * </pre>
/// * 
/// * For more information, see <seealso cref="GraphDatabaseService"/>. </summary>
/// 
	public sealed class EmbeddedGraphDatabase : IGraphDatabaseService
	{
		private readonly EmbeddedGraphDbImpl neoImpl;

///    
///     <summary> * Creates an embedded <seealso cref="GraphDatabaseService"/> with a store located in
///     * <code>storeDir</code>, which will be created if it doesn't already exist.
///     *  </summary>
///     * <param name="storeDir"> the store directory for the Neo4j store files </param>
///     
		public EmbeddedGraphDatabase(string storeDir)
		{
			this.neoImpl = new EmbeddedGraphDbImpl(storeDir, this);
		}

///    
///     <summary> * A non-standard way of creating an embedded <seealso cref="GraphDatabaseService"/>
///     * with a set of configuration parameters. Will most likely be removed in
///     * future releases.
///     * <p>
///     * Creates an embedded <seealso cref="GraphDatabaseService"/> with a store located in
///     * <code>storeDir</code>, which will be created if it doesn't already exist.
///     *  </summary>
///     * <param name="storeDir"> the store directory for the db files </param>
///     * <param name="params"> configuration parameters </param>
///     
        public EmbeddedGraphDatabase(string storeDir, Dictionary<string, string> @params)
		{
			this.neoImpl = new EmbeddedGraphDbImpl(storeDir, @params, this);
		}

///    
///     <summary> * A non-standard convenience method that loads a standard property file and
///     * converts it into a generic <Code>Map<String,String></CODE>. Will most
///     * likely be removed in future releases.
///     *  </summary>
///     * <param name="file"> the property file to load </param>
///     * <returns> a map containing the properties from the file </returns>
///     * <exception cref="IllegalArgumentException"> if file does not exist </exception>
///     
        public static Dictionary<string, string> LoadConfigurations(string file)
		{
			return EmbeddedGraphDbImpl.LoadConfigurations(file);
		}

		public Node CreateNode()
		{
			return neoImpl.CreateNode();
		}

		public Node GetNodeById(long id)
		{
			return neoImpl.GetNodeById(id);
		}

		public Relationship GetRelationshipById(long id)
		{
			return neoImpl.GetRelationshipById(id);
		}

		public Node GetReferenceNode()
		{
			return neoImpl.GetReferenceNode();
		}

		public void Shutdown()
		{
			neoImpl.shutdown();
		}

		public bool EnableRemoteShell()
		{
			return neoImpl.EnableRemoteShell();
		}

		public bool EnableRemoteShell(Dictionary<string, object > initialProperties)
		{
			return neoImpl.EnableRemoteShell(initialProperties);
		}

		public IEnumerable<RelationshipType> GetRelationshipTypes()
		{
			return neoImpl.getRelationshipTypes();
		}

///    
///     * <exception cref="TransactionFailureException"> if unable to start transaction </exception>
///     
		public Transaction BeginTx()
		{
			return neoImpl.BeginTx();
		}

///    
///     <summary> * Returns a non-standard configuration object. Will most likely be removed
///     * in future releases.
///     *  </summary>
///     * <returns> a configuration object </returns>
///     
		public Config GetConfig()
		{
			return neoImpl.GetConfig();
		}

		public override string ToString()
		{
			return base.ToString() + " [" + neoImpl.getStoreDir() + "]";
		}

		public string GetStoreDir()
		{
			return neoImpl.getStoreDir();
		}

		public IEnumerable<Node> GetAllNodes()
		{
			return neoImpl.GetAllNodes();
		}
	}
}